/*
 * @Author: xuhongling
 * @Date:   2020-12-15 14:16:18
 * @Last Modified by:   xuhongling
 * @Last Modified time: 2024-01-29 09:22:17
 */
import type { Map } from 'ol';
// 清除地图图层要素
export default function (globalMap: Map, layerName: string) {
  const layers = globalMap.getLayers();
  const localTargetLayer: Array<any> = [];
  layers.forEach((layer: any) => {
    if (layer.getProperties().layerName !== undefined) {
      const isLegendPointVectorLayer = layer.getProperties().layerName.includes(layerName);
      if (isLegendPointVectorLayer) {
        layer.getSource().clear();
        localTargetLayer.push(layer);
      }
    }
  });
  localTargetLayer.forEach((layer) => {
    globalMap.removeLayer(layer);
  });
}
